import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/http_data.dart';
import 'package:app/src/http/bean/wroks/address_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/ui/route/helper/route_helper.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

import '../../../../../../http/bean/worksdo/equipment_management_bean.dart';
import '../../../../../../http/bean/worksdo/material_requisition_bean.dart';
import '../../../../../../http/bean/wroks/dispatchingaudit_bean.dart';
import '../../../../../../http/model/config_model.dart';
import '../../../../../app_ui.dart';
import '../../../../../dialog/dailog.dart';

///设备报修
class UiMyWorkOrder {
  ///data 信息
  ///oldData 历史信息
  static Widget build(BuildContext context,
      GetMyRepairOrderInfoBean? myRepairOrderInfoBean, StateSetter setState,
      {String? title}) {
    EquipmentInfo? data = myRepairOrderInfoBean?.OrderInfo;
    EquipmentInfo? oldData = null;
    if (data == null) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).Equipmentrepair; //设备报修
    }
    children.add(UiBase.title(context, title)); //标题
    var isAllowEmpty = true;
    var isGrey = false;
    var defaultValue = ""; //文本为空时，显示默认文本。
    children.add(UiBase.item(context, AppStrings.of(context).Devicecoding,
        data?.EquipmentCode1, oldData?.EquipmentCode1,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //设备编码
    children.add(UiBase.item(context, AppStrings.of(context).Devicename,
        data?.EquipmentName1, oldData?.EquipmentName1,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //设备名称
    children.add(UiBase.item(context, AppStrings.of(context).Equipmenttype,
        data?.Model, oldData?.Model,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //设备型号
    children.add(UiBase.item(context, AppStrings.of(context).manufacturer,
        data?.ManufacturerName, oldData?.ManufacturerName,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //制造商
    children.add(UiBase.item(context, AppStrings.of(context).manufacturer2,
        data?.SupplierName, oldData?.SupplierName,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //供应商
    children.add(UiBase.item(context, AppStrings.of(context).process2,
        data?.ProcessName, oldData?.ProcessName,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //所属工艺
    children.add(UiBase.item(context, AppStrings.of(context).Devicestatus,
        data?.EquipmentType, oldData?.EquipmentType,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //设备状态
    children.add(UiBase.item(
        context,
        AppStrings.of(context).Installationposition,
        data?.InstallPosition,
        oldData?.InstallPosition,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //安装位置
    // var FactoryName = AppDataConfig.getFactory()?.FactoryName ?? "";
    children.add(UiBase.item(context, AppStrings.of(context).Ownedfactory,
        data?.FactoryName, oldData?.FactoryName,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //所属工厂
    children.add(UiBase.item(context, AppStrings.of(context).Installationtime,
        data?.InstallDate, oldData?.InstallDate,
        isAllowEmpty: isAllowEmpty,
        defaultValue: defaultValue,
        isGrey: isGrey)); //安装时间

    ///工单号和工单类型，那个设备维修就显示在哪一级。
    if (data.isLv1()) {
      children.add(UiBase.item(context, AppStrings.of(context).TicketNo,
          data?.RepairNo, oldData?.RepairNo,
          isAllowEmpty: isAllowEmpty,
          defaultValue: defaultValue,
          isGrey: isGrey)); //工单号
      children.add(UiBase.item(
          context,
          AppStrings.of(context).Workordertype,
          data?.getRepairTypeName(context),
          oldData?.getRepairTypeName(context),
          isAllowEmpty: isAllowEmpty,
          defaultValue: defaultValue,
          isGrey: isGrey)); //工单类型
      children.add(UiBase.item(context, AppStrings.of(context).collaborator,
          myRepairOrderInfoBean?.getCollaboratorName(), null,
          isAllowEmpty: isAllowEmpty,
          defaultValue: defaultValue,
          isGrey: isGrey)); //协同人员
      children.add(UiBase.item(
          context,
          AppStrings.of(context).Estimatedworkinghours2_,
          "${myRepairOrderInfoBean?.getWorkHours()}\t${AppStrings.of(context).hours}",
          null,
          isAllowEmpty: isAllowEmpty,
          defaultValue: defaultValue,
          isGrey: isGrey)); //预计工时
    }
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }
}
